/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nurdrobotics;

import edu.wpi.first.wpilibj.*;
// air compresor
/**
 *
 * @author hpadmin
 */
public class Wedge {
    // The following variables give names to channels on the solenoid
    // breakout board.
    // This way, it's easy to look at this section of code to make sure that
    // the solenoids are connected to the correct channel.
    private static final int SOLENOID_CHANNEL_DEPLOY = 1;
    private static final int SOLENOID_CHANNEL_RETRACT = 2;

    private static Compressor m_compressor = null;
    private static Solenoid m_deploySolenoid = null;
    private static Solenoid m_retractSolenoid = null;
    private static boolean m_isDeployed = false;

    static {
        /*
         * Create the two solenoids used to deploy and retract the wedge
         */
        m_deploySolenoid = new Solenoid(SOLENOID_CHANNEL_DEPLOY);
        m_deploySolenoid.set(false);
        m_retractSolenoid = new Solenoid(SOLENOID_CHANNEL_RETRACT);
        m_retractSolenoid.set(false);

        /*
         * Create the air compressor used to keep the tank filled
         */
        m_compressor = new Compressor(DigitalSidecar.INPUT_PRESSURE_SWITCH,
                DigitalSidecar.RELAY_COMPRESSOR);

        /*
         * Start the compressor running. It will automatically turn on
         * and off based on the pressure switch that was supplied when
         * the compressor object was created
         */
        m_compressor.start();
    }

    /*
     * Deploy the wedge
     */
    public static void deploy() {
        m_deploySolenoid.set(true);
        m_retractSolenoid.set(false);
        m_isDeployed = true;
    }

    /*
     * Retract the wedge
     */
    public static void retract() {
        m_deploySolenoid.set(false);
        m_retractSolenoid.set(true);
        m_isDeployed = false;
    }

    /*
     * Returns true if the wedge is deployed, false otherwsise
     */
    public static boolean isDeployed() {
        return m_isDeployed;
    }

    /*
     * Returns true if the wedge is retracted, false otherwsise
     */
    public static boolean isRetracted() {
        return !isDeployed();
    }

    /**
     * This function is called continuously while in teleoperated mode
     */
    public static void teleopUpdate() {
        // check to see whether we should deploy or retract the wedge
        if (DriverStick.deployWedgePressed() == true) {
            Wedge.deploy();
        }
        else if (DriverStick.retractWedgePressed() == true) {
            Wedge.retract();
        }
    }
}
